<?php
defined('_JEXEC') or die('Restricted access');
$cparams =& JComponentHelper::getParams('com_media');
$contents = $this->contents;
$section = $this->section;
JHTML::stylesheet('',JaNewsHelper::getFile('ja.news.css','components/com_janews/layouts/blog/'.$this->bparams->template.'/assets/','components/com_janews/assets/'));
?>
<?php if ($this->bparams->params->get('show_page_title')) : ?>
<h1 class="componentheading<?php echo $this->bparams->params->get('pageclass_sfx');?>">
	<?php echo $this->escape($this->bparams->params->get('page_title')); ?>
</h1>
<?php endif; ?>

<?php if ($section):?>
  <?php if ($this->bparams->params->def('show_description', 1) || $this->bparams->params->def('show_description_image', 1)) :?>
  <div class="jazin-pagedesc clearfix">
  	<?php if ($this->bparams->params->get('show_description_image') && $section->image) : ?>
  		<img src="<?php echo $this->baseurl . '/' . $cparams->get('image_path') . '/'. $section->image;?>" align="<?php echo $section->image_position;?>" hspace="6" alt="" />
  	<?php endif; ?>
  	<?php if ($this->bparams->params->get('show_description') && $section->description) : ?>
  		<?php echo $section->description; ?>
  	<?php endif; ?>
  </div>
  <?php endif; ?>
<?php endif; ?>

<?php $i = $this->pagination->limitstart;?>
<?php
$startIntroArticles = $this->pagination->limitstart;
$numIntroArticles = $startIntroArticles + $this->bparams->params->get('introitems', 4);
if (($numIntroArticles != $startIntroArticles) && ($i < $this->total)) : ?>
<div id="jazin-wrap">
<div id="jazin" class="clearfix">
		<?php
			$divider = '';
			$cols = $this->bparams->params->get('columns', 2);
			$news = $this->bparams->params->get('introitems', 4);
			if($news > ($this->total - $i)) $news = $this->total - $i;
			if($news < $cols) $cols = $news;
			if (!$cols) return;
			$width = 99.9/$cols;

      $this->maxchar = $this->bparams->params->get('maxchars',0);
      if($cols == 1) $this->maxchar = 0;

      $c = 0;
			for ($index =0; $index < $news; $index++){
			  $colArr[$c][] = $index;
			  $c = ($c < ($cols - 1)) ? $c + 1 : 0;
			}

      
			for ($z = 0; $z < $cols; $z ++) :
			  $cls = $cols==1?'full':($z==0?'left':($z==$cols-1?'right':'center'));
				if ($z > 0) : $divider = " column_separator"; endif; ?>

				<div class="jazin-<?php echo $cls;?>" style="width:<?php echo $width;?>%">
				<?php /*
				$min = (int) ($news / $cols);
				$adds = $news - $min*$cols;
				for ($y = 0; $y < $min ; $y ++) :
					if ($i < $this->total && $i < ($numIntroArticles)) :
						$this->item = $this->getItem($i, $this->bparams->params);//$contents[$i];//$i, $params);
						include('blog_item.php');//echo $this->loadTemplate('item');
						$i ++;
					endif;
				endfor;
				if ($z < $adds){
				  if ($i < $this->total && $i < ($numIntroArticles)) :
						$this->item = $this->getItem($i, $this->bparams->params);//$contents[$i];//$i, $params);
						include('blog_item.php');//echo $this->loadTemplate('item');
						$i ++;
					endif;
				}*/
				foreach ($colArr[$z] as $i){
				  if ($i < $this->total && $i < ($numIntroArticles)) :
						$this->item = $this->getItem($i, $this->bparams->params);//$contents[$i];//$i, $params);
						include('blog_item.php');//echo $this->loadTemplate('item');
						$i ++;
					endif;
				}
				?>
				</div>
		  <?php endfor; ?>
</div>
</div>
<?php endif; ?>

<?php if ($this->bparams->params->get('linkitems') && ($i < $this->total)) : ?>
<div id="jazin-more">
		<div class="blog_more<?php echo $this->bparams->params->get('pageclass_sfx') ?>">
			<?php
				$this->links = array_splice($contents, $news, $this->bparams->params->get('linkitems', 4));
			?>
  			<div>
        	<strong><?php echo JText::_( 'More Articles...' ); ?></strong>
        </div>
        <ul>
        <?php
         foreach ($this->links as $link) : ?>
        	<li>
        		<a class="blogsection" href="<?php echo JRoute::_('index.php?option=com_content&view=article&id='.$link->slug); ?>">
        			<?php echo $link->title; ?></a>
        	</li>
        <?php endforeach; ?>
        </ul>
		</div>
</div>
<?php endif; ?>

<?php if ($this->bparams->params->def('show_pagination', 2)) : ?>
<div class="jazin-pagenav">
		<?php echo $this->pagination->getPagesLinks(); ?>
</div>
<?php endif; ?>

<?php if ($this->bparams->params->def('show_pagination_results', 1)) : ?>
<div class="jazin-pagenav-counter">
		<?php echo $this->pagination->getPagesCounter(); ?>
</div>
<?php endif; ?>
